import httpManager, { RequestMethod } from '../utils/requestHttp';

const BASE_URL = 'https://www.wanandroid.com';

const API = {
  register: '/user/register',
  login: '/user/login',
  logout: '/user/logout/json',
  banner: '/banner/json',
  friend: '/friend/json',
}

// 注册
export const register = async (params: object) => {
  const data = await httpManager.getInstance().request({
    method: RequestMethod.POST,
    url: BASE_URL + API.register,
    extraData: params
  })
  return data;
}

// 登录
export const login = async (params: object) => {
  const data = await httpManager.getInstance().request({
    method: RequestMethod.POST,
    url: BASE_URL + API.login,
    extraData: params
  })
  return data;
}

// 登出
export const logOut = async () => {
  const data = await httpManager.getInstance().request({
    method: RequestMethod.GET,
    url: BASE_URL + API.logout,
  })
  return data;
}

// 获取banner
export const getBanner = async (params: object) => {
  const data = await httpManager.getInstance().request({
    method: RequestMethod.GET,
    url: BASE_URL + API.banner,
  })
  return data;
}

// 获取首页文章列表
export const getHomeArticleList = async (page = 0) => {
  const data = await httpManager.getInstance().request({
    method: RequestMethod.GET,
    url: `${BASE_URL}/article/list/${page}/json`
  })
  return data;
}

// 常用网站
export const getFriendList = async () => {
  const data = await httpManager.getInstance().request({
    method: RequestMethod.GET,
    url: BASE_URL + API.friend
  })
  return data;
}

/**
 * 获取公众号列表
 * return name
 * return id
 * */
export const getWXchartList = async (page = 0) => {
  const data = await httpManager.getInstance().request({
    method: RequestMethod.GET,
    url: `${BASE_URL}/wxarticle/chapters/json`
  })
  return data;
}

// 获取公众号详情
export const getWXchartDetailList = async (id: number, page = 0) => {
  const data = await httpManager.getInstance().request({
    method: RequestMethod.GET,
    url: `${BASE_URL}/wxarticle/list/${id}/${page}/json`
  })
  return data;
}

// export const getBanner = () => {}
//
// export const getBanner = () => {}
//
// export const getBanner = () => {}
